
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="approvalProcess/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="approvalProcess/css/commonly-used-show.css" />
    <script type="text/javascript" src="approvalProcess/js/jquery.min.js"></script>
    <script type="text/javascript" src="approvalProcess/js/bootstrap.js" ></script>

    <script type="text/javascript" src="approvalProcess/js/jquery.cookie.js"></script>

    <link rel="stylesheet" type="text/css" href="approvalProcess/css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="approvalProcess/css/modal.css" />
    <script type="text/javascript" src="approvalProcess/js/modal.js" ></script>

    <!--  分页显示 -->
    <script src="approvalProcess/js/jqPaginator.min.js" type="text/javascript"></script>
    <link href="approvalProcess/css/myPage.css" rel="stylesheet" type="text/css" />
    <script src="approvalProcess/js/myPage.js" type="text/javascript"></script>



    <title>学校资讯</title>

    <style>
        .newsdiv{
            border: 1px solid black;
            margin: 30px auto;
            height: 150px;
            padding: 40px;
            border-radius: 5px;
        }
    </style>
</head>

<body class="mybody">

<jsp:include page="theTopMenuAdmin.jsp" />


<div class="container-fluid">
    <div class="row">


        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">



                            <div >
     <h3 style="text-align: center">学校资讯</h3>
     <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3"/>
    <div id="personal_user" style="margin-left: 10%; margin-right: 10%">

         <div id="my_news">

            </div>



        <div class="text-center">

          <div style="margin-top: 20px;">

                                    <div style="float: left; margin-left: 130px;" class="col-lg-4 ">
                <div class="input-group">
                    <input id="user_find" type="text" class="form-control" placeholder="新闻标题查找">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" onclick="findUse()">查找</button>
                    </span>
                </div>
            </div>

                                    <div style="float: right; margin-right: 100px;">
                                        <a class="btn btn-primary" href="${pageContext.request.contextPath}/adminLatestNews?id=1">添加资讯</a>
                                    </div>

                                    <div style="clear: both">

                                    </div>

                                </div>

                                <div style="margin-top: 20px;">
                                    <span id="user_messge" style="font-size:10px; color: red;"></span>
                                </div>

                                <div>
                                    <ul class="pagination" id="pagination"></ul>
                                    <!--PageCount是一共多少条数据-->
                                    <input type="hidden" id="PageCount" />
                                    <!--PageSize是页面显示多少条数据-->
                                    <input type="hidden" id="PageSize" value="6"/>
                                    <!--countindex这个参数是通过上面的PageCount与PageSize计算出来的分多少页-->
                                    <!--js中是自动计算的，可默认也可以自己填-->
                                    <input type="hidden" id="countindex" value="10"/>
                                    <!--上一页与下一页中间的数字框，要显示几个就value多少个-->
                                    <input type="hidden" id="visiblePages" value="7"/>
                                </div>

                             </div>



        </div>

</div>




                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>


<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    //设置全局变量
    var numes = 1;
    var isok = true;


    /*loadData(num,count)写在$(function(){})外，num为当前选中页码，count是我自己加的，是ajax返回的数据总数*/
    function loadData(num, count) {
        numes = num;
        if (count){
            $("#PageCount").val(count);
        }else {
            $("#PageCount").val("5");
        }

        //当点击首页，下一页，上一页，尾页，数字页码时执行ajax数据操作
        if (numes !== 1){
            newsInfo();
        }else if (numes === 1){
            newsInfo();
        }

    }

    //输入查找的条件时进行查找操作
    function findUse(){
        isok = true;
        newsInfo();
    }

    //每当数据发生变动时进行页面的刷新
    function uppag(count){
        //重新加载分页控件
        loadData(1, count);
        loadpage();
        isok = false;
    }

    window.onload = function(){
        newsInfo();
    }

    function newsInfo(){
        var postUrl = "${pageContext.request.contextPath}/selectNewsAll";

        var str = {
            "pageResult": {
                "currentPage": numes,
                "pageSize": 6
            },
            "newsTitle": $("#user_find").val()
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    $("#user_messge").text(data.msg);

                    $("#my_news").html("");
                    if (data.msg === "查询失败,无该数据"){
                        uppag(0);
                    }
                }else {

                    //全局变量，第一次加载后就不执行了，当用户进行查找操作时在继续执行
                    if (isok){
                        uppag(data.result.totalSize);
                    }

                    var strtab = "";
                    //清空表格数据
                    $("#my_news").html("");

                    var conter = 1;
                    for (var i = 0; i < data.result.items.length; i++) {

                        strtab = "<div class='newsdiv alert alert-info'>" +
                "<div style='float: left; margin-left: 10px;'>" +
                    "<a href='#' >" +
                        "<span>" + "标题：" + data.result.items[i].newsTitle + "</span>" +
                    "</a>" +
                    "<p style='margin-top: 20px'>" +
                            "<span>" + "发布者：" + data.result.items[i].newsIssuer + "</span>" +
                        "<span style='margin-left: 200px;'>" + "发布时间：" + data.result.items[i].createTime + "</span>" +
                    "</p>" +
                "</div>" +
                 "<div style='float: right; '>" +
                     "<a class='btn btn-default btn-sm' href='${pageContext.request.contextPath}/adminLatestNews?id=" + data.result.items[i].id + "'>修改</a>" +
                      "<br>" +
                      "<br>" +
                     "<a class='btn btn-default btn-sm' href='javascript:void(0);' onclick="+ "deletNwes('" + data.result.items[i].id + "')" + ">删除</a>" +
                 "</div>" +
             "</div>" +
              "<div style='clear: both'>" +
               "</div>"
                        ;

                        $("#my_news").append(strtab);//将数据追加

                        conter++;
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }



    function deletNwes(datees){

        var mModal2 = new mModal({
            top: "40vh",
            content: "你确定要删除此项？",
            confirm: function () {
                deletNwes1(datees);
                mModal2.close();
            },
            cancel: function () {
            }
        });

        mModal2.renderDom();

    }

    function deletNwes1(id){
        var postUrl = "${pageContext.request.contextPath}/deletNwes";
        var str = {
            "id": id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    $("#user_messge").text(data.msg);
                }else {
                    location.reload();
                }
            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>